#! /bin/bash

kvm_setup_powerpc () {
    if grep '^platform[[:space:]]*:[[:space:]]*PowerNV' /proc/cpuinfo > /dev/null; then
	# PowerNV platform, which is KVM HV capable

	if [ -z "$SUBCORES" ]; then
	    SUBCORES=1
	fi

	# Step 1. Load the KVM HVmodule
	if ! modprobe -b kvm_hv; then
	    return
	fi

	# Step 2. Configure subcore mode
	# FIXME: Should we check for POWER8 first?
	/usr/sbin/ppc64_cpu --subcores-per-core=$SUBCORES

	# Step 3. Disable SMT (multithreading)
	/usr/sbin/ppc64_cpu --smt=off
    fi
}

case $(uname -m) in
    ppc64|ppc64le)
	kvm_setup_powerpc
	;;
esac

exit 0
